package com.shenhaofeng.app.http.request;

import java.io.File;


/**
 * Created by Administrator on 2016/10/13.
 */
public class FileBody extends RequestBody {


    private File file;

    private MediaType mediaType;


    protected FileBody(File file, MediaType mediaType) {
        this.file = file;
        this.mediaType = mediaType;
    }


    public File file() {
        return file;
    }


    @Override
    public MediaType contentType() {
        return mediaType;
    }


    public static class Builder {


        private String filename;

        private File file;

        private MediaType mediaType;


        public Builder file(File file) {
            this.file = file;
            if (filename == null || filename.isEmpty()) {
                this.filename = file.getName();
            }
            return this;
        }


        public Builder mediaType(MediaType mediaType) {
            this.mediaType = mediaType;
            return this;
        }


        public FileBody build() {
            return new FileBody(file, mediaType);
        }
    }


}
